package com.yanqu.road.web.entity;

import com.yanqu.road.entity.activity.SimpleActivityInfo;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class AllActivity {

    Map<Integer, List<SimpleActivityInfo>> serverIdActivityInfoMap;
    Map<Integer, List<SimpleActivityInfo>> typeActivityInfoMap;

    public AllActivity(Map<Integer, List<SimpleActivityInfo>> serverIdActivityInfoMap, Map<Integer, List<SimpleActivityInfo>> typeActivityInfoMap) {
        this.serverIdActivityInfoMap = serverIdActivityInfoMap;
        this.typeActivityInfoMap = typeActivityInfoMap;
    }

    public Map<Integer, List<SimpleActivityInfo>> getServerIdActivityInfoMap() {
        return serverIdActivityInfoMap;
    }

    public void setServerIdActivityInfoMap(Map<Integer, List<SimpleActivityInfo>> serverIdActivityInfoMap) {
        this.serverIdActivityInfoMap = serverIdActivityInfoMap;
    }

    public Map<Integer, List<SimpleActivityInfo>> getTypeActivityInfoMap() {
        return typeActivityInfoMap;
    }

    public void setTypeActivityInfoMap(Map<Integer, List<SimpleActivityInfo>> typeActivityInfoMap) {
        this.typeActivityInfoMap = typeActivityInfoMap;
    }

    public List<Integer> getActivityIdListByServerId(int serverId, long serverTime) {
        if (!serverIdActivityInfoMap.containsKey(serverId)) {
            return new ArrayList<>();
        }
        List<Integer> activityIdList = new ArrayList<>();
        for (SimpleActivityInfo simpleActivityInfo : serverIdActivityInfoMap.get(serverId)) {
            if (simpleActivityInfo.getEndShowTime() > (serverTime - 30 * 24 * 60 * 60)) {
                activityIdList.add(simpleActivityInfo.getActivityId());
            }
        }
        return activityIdList;
    }


    public List<Integer> getActivityIdListByServerIdAndType(int serverId, List<Integer> types, long serverTime) {
        List<Integer> activityIdList = new ArrayList<>();
        for (int type : types) {
            if (typeActivityInfoMap.containsKey(type)) {
                for (SimpleActivityInfo simpleActivityInfo : typeActivityInfoMap.get(type)) {
                    if (serverTime >= simpleActivityInfo.getBeginShowTime() && serverTime < simpleActivityInfo.getEndShowTime()) {
                        if (simpleActivityInfo.getServerIdList().contains(serverId)) {
                            activityIdList.add(simpleActivityInfo.getActivityId());
                        }
                    }
                }
            }
        }
        return activityIdList;
    }
}
